<template>
  <page-main class="page-patient-list">
    <div class="hd">
      <h3>请选择就诊人</h3>
    </div>
    <van-cell-group inset v-for="(item,index) in list" :key="index">
      <van-cell :border="false" :label="item.idNo" @click="gotoPage(item)">
        <div class="title" slot="title">
          <span>{{item.custName}}</span>
          <van-tag round class="tag-blue-light m-l-5">{{$util.setName(item.relationType, init_data.relationType_list)}}</van-tag>
        </div>
        <span v-if="item.isDefault == '1'">默认就诊人</span>
      </van-cell>
    </van-cell-group>
  </page-main>
</template>

<script>
export default {
  data(){
    return {
      from: null,
      list:[],
      init_data:{},
    }
  },
  created(){
    this.from = this.$route.query.from;
    this.getInitData();
    this.getList();
  },
  methods:{
    async getInitData(){
      this.init_data.relationType_list = await this.$util.getDictList('relation_type');
    },
    gotoPage(item){      
      if(this.from == 'appointment'){
        this.$store.commit('setCurrentPatient', item);
        localStorage.setItem('currentPatient', JSON.stringify(item));
        this.$util.gotoPage('/office/index',{patientId: item.patientId});
      }else{
        this.$store.commit('setCurrentPatient', item);
        localStorage.setItem('currentPatient', JSON.stringify(item));
        this.$router.go(-1);
      }
    },
    getList(){
      this.$http('get', '/admin/custApi/getPatientsList', {}, (data,msg) => {
        this.list = data;
        if(data.length == 0){
          this.$dialog.confirm({
            title: '提示',
            message: '请先去添加就诊人',
          }).then(() => {
            this.$util.gotoPage('/patient/list');
          });
        }
      })
    },
  }
}
</script>

<style>

</style>